/**
 * Name: ParamReader
 * Datum: 20.06.2011
 * Autor: Wilfried Karch
 * Zweck: Hilfsklasse zum "Parsen" des Inputs aus dem HTTP-Request-Body.
 */

package fhj.swd09.resteasy.experiments;

public class ParamReader 
{
	//Property delimiter:Character
	private Character delimiter;
	public Character getDelimiter() 
	{
		return delimiter;
	}
	public void setDelimiter(Character delimiter)
	{
		this.delimiter = delimiter;
	}


	//Methode um die Eigenschaften aus einem Plaintext-Input zu extrahieren. 
	public Fact readFact(String input) 
    {
		Fact f = new Fact();
    	int delpos = input.indexOf(this.getDelimiter());			   
		
		f.setText(input.substring(0, delpos));
		
		input = input.substring(delpos+1);
		delpos = input.indexOf(this.getDelimiter());
		if (input.substring(0, delpos).equalsIgnoreCase("true"))
		{
			f.setFavourite(true);
		}
		else
		{
			f.setFavourite(false);
		}
		input = input.substring(delpos+1);
		
		f.setCategory(input);
		   
		return f;
	}
}
